﻿using Kendo.Mvc.Extensions;
using Kendo.Mvc.UI;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

using CallCenter.Data;
using CallCenter.Data.BizUtilities;
using System.Configuration;
using System.Data;
using CallCenter.Security;
using CallCenter.Data.Models;
using CallCenter.Data.Misc;

namespace CallCenter.Web.Controllers
{
    public class ContactMessagesController : BaseController
    {
        // GET: ContactMessages
        public ActionResult Index()
        {
            return View();
        }

        public JsonResult GetContactMSG(int id)
        {
            var scratchPads = this.Bridge.CommunicationUtility.GetContactMSG(id, 24);
            return Json(scratchPads, JsonRequestBehavior.AllowGet);
        }
        [HttpGet]
        public JsonResult GetAllCompanies()
        {
            var scratchPads = this.Bridge.ContactDetailUtility.GetAllCompanies();
            return Json(scratchPads, JsonRequestBehavior.AllowGet);
        }

        [HttpPost]
        public JsonResult CreateContactMessages(ContactCompanyMessageVM model)
        {
         


            int userId = this.Bridge.AccountUtility.GetUserIDByUserNames(User.Identity.Name.ToLower());
            model.userID = userId;
            var returnMessage = this.Bridge.ContactDetailUtility.InsertToContactMessages(model);
            if (!returnMessage.Status)
                ModelState.AddModelError("Error", returnMessage.Message);
            else {
                return Json(new AjaxSuccess { Message = "Success" }, JsonRequestBehavior.AllowGet);
            }
         

            return Json(new AjaxFailure { Errors = ModelState.SerializeErrors }, JsonRequestBehavior.DenyGet);
        }

        [HttpPost]
        public JsonResult UpdateContactMessages(ContactCompanyMessageVM model)
        {
            int userId = this.Bridge.AccountUtility.GetUserIDByUserNames(User.Identity.Name.ToLower());
            model.userID = userId;
            var returnMessage = this.Bridge.ContactDetailUtility.UpdateToContactMessages(model);
            if (!returnMessage.Status)
                ModelState.AddModelError("Error", returnMessage.Message);
            else {
                return Json(new AjaxSuccess { Message = "Success" }, JsonRequestBehavior.AllowGet);
            }
          

            return Json(new AjaxFailure { Errors = ModelState.SerializeErrors }, JsonRequestBehavior.DenyGet);
        }
        [HttpPost]
        public JsonResult DeleteCompanyContactMessages(ContactCompanyMessageVM model)
        {
          
            int id = model.id;
            this.Bridge.ContactDetailUtility.delete(id);
            var returnMessage = "Success";
            return Json(returnMessage, JsonRequestBehavior.AllowGet);

        }
    }
}